package com.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.dao.DataAccessException;

import com.model.Cliente;
import com.query.ClienteQuery;

public class ClienteDAOImpl extends BaseHibernateDAO<Cliente, ClienteQuery> {

	@Override
	public Class<Cliente> getModelClass() {
		return Cliente.class;
	}

	@Override
	public List<String> getListNames() {
		List<String> list = new ArrayList<String>();
		list.add("listaContactos");
		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Cliente> getList(String query) throws DataAccessException {
		List<Cliente> list = null;

		DetachedCriteria criteria = DetachedCriteria.forClass(Cliente.class);

		criteria.add(Restrictions.or(Restrictions.eq("cuit", query),
				Restrictions.eq("dni", query)));

		list = (List<Cliente>) getHibernateTemplate().findByCriteria(criteria);
		return list;
	}

}
